package com.orange.studio.dbk.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {
	
	public static final String DB_NAME = "KaraokeORADB.db";
	public static final String DB_EXTENSION = ".db";
	private static final int VERSION_SOCIAL = 1;
	private static final int DATABASE_VERSION = VERSION_SOCIAL;
	
	public static final String TABLE_LIST_SONGS="song";
	public static final String TABLE_SONG_RECORDS_COLUMN_ID="_id";
	public static final String TABLE_SONG_RECORDS_COLUMN_NAME="sname";
	public static final String TABLE_SONG_RECORDS_COLUMN_NAMECLEAN="snameclean";
	public static final String TABLE_SONG_RECORDS_COLUMN_ABBR="sabbr";
	public static final String TABLE_SONG_RECORDS_COLUMN_MANUFACTURE="smanufacture";
	public static final String TABLE_SONG_RECORDS_COLUMN_LANGUAGE="slanguage";
	public static final String TABLE_SONG_RECORDS_COLUMN_LYRIC="slyric";
	public static final String TABLE_SONG_RECORDS_COLUMN_LYRIC_CLEAN="slyricclean";
	public static final String TABLE_SONG_RECORDS_COLUMN_META="smeta";
	public static final String TABLE_SONG_RECORDS_COLUMN_MEACLEAN="smetaclean";
	public static final String TABLE_SONG_RECORDS_COLUMN_LIKED="sliked";
	public static final String TABLE_SONG_RECORDS_COLUMN_VOL="svol";
	
	public static final String TABLE_LIST_FAVIORITES="faviorites";
	public static final String TABLE_FAVIORITES_RECORDS_COLUMN_ID="_id";
	public static final String TABLE_FAVIORITES_RECORDS_COLUMN_SONG_ID="songId";
	public static final String TABLE_FAVIORITES_RECORDS_COLUMN_USER_ID="userId";
	public static final String TABLE_FAVIORITES_RECORDS_COLUMN_RATING="score";
	public static final String TABLE_FAVIORITES_RECORDS_COLUMN_DATE_CREATED="dateCreated";
	
	private static final String DATABASE_CREATE_TABLE_SONGS="create table "
			+TABLE_LIST_SONGS+" ("
			+TABLE_SONG_RECORDS_COLUMN_ID+" integer primary key, "
			+TABLE_SONG_RECORDS_COLUMN_NAME+ " text, " 
			+TABLE_SONG_RECORDS_COLUMN_NAMECLEAN+" text, " 
			+TABLE_SONG_RECORDS_COLUMN_ABBR+" text, " 
			+TABLE_SONG_RECORDS_COLUMN_MANUFACTURE+" integer not null, "
			+TABLE_SONG_RECORDS_COLUMN_LANGUAGE+" text, " 
			+TABLE_SONG_RECORDS_COLUMN_LYRIC+" text, " 
			+TABLE_SONG_RECORDS_COLUMN_LYRIC_CLEAN+" text, " 
			+TABLE_SONG_RECORDS_COLUMN_META+" text, " 
			+TABLE_SONG_RECORDS_COLUMN_MEACLEAN+" text, "
			+TABLE_SONG_RECORDS_COLUMN_LIKED+" smallint, "
			+TABLE_SONG_RECORDS_COLUMN_VOL+" integer not null " 
			+ ");";
	
	public DatabaseHelper(Context context){
		super(context,DB_NAME,null,DATABASE_VERSION);
	}
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE_TABLE_SONGS);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if(newVersion!=VERSION_SOCIAL){
			Log.w(DatabaseHelper.class.getName(), "Upgrading database from version "
					+ oldVersion + " to " + newVersion
					+ ", which will destroy all old data");
			db.execSQL("DROP TABLE IF EXISTS " + TABLE_LIST_SONGS);
			onCreate(db);
		}else{
			
		}
	}
}
